<?php
namespace api\festival\controller;

use cmf\controller\RestBaseController;
use think\Db;

class IndexController extends RestBaseController{
    
    public function __construct(){
        parent::__construct();
    }
    
    /**
     * 获取一级分类
     */
    public function getFestivals(){
        $data = Db::name('festival')->where('is_del', 0)
            ->where('parent_id', 0)->order('date ASC')->select()->toArray();
        $this->success('1', $data);
    }
    
    /**
     * 获取二级分类
     */
    public function getChild(){
        $post = $this->request->post();
        $data = Db::name('festival')->where('is_del', 0)
            ->where('parent_id', $post['id'])->select()->toArray();
        $this->success('1', $data);
    }
    
    /**
     * 获取内容图片列表
     */
    public function getList(){
        $post = $this->request->post();
        $data = Db::name('images')->where('cid', $post['cid'])->column('img');
        $this->success('成功', $data);
    }
    
    
    /**
     * 智能推荐
     */
    public function smartOrder(){
        
    }
    
    /**
     * 获取详情内容
     */
    public function showView(){
        $post = $this->request->post();
        $data = Db::name('content')->where('fid', $post['id'])->find();
        $images = array();
        if($data['image1']){
            $images[] = $data['image1'];
        }
        if($data['image2']){
            $images[] = $data['image2'];
        }
        if($data['image3']){
            $images[] = $data['image3'];
        }
        if($data['image4']){
            $images[] = $data['image4'];
        }
        if($data['image5']){
            $images[] = $data['image5'];
        }
        if($data['image6']){
            $images[] = $data['image6'];
        }
        $data['images'] = $images;
        $this->success('成功', $data);
    }

}